SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_pistol.mdl"
SWEP.WorldModel			= "models/weapons/w_pistol.mdl"

SWEP.Weight				= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false

SWEP.Primary.Recoil			= 1
SWEP.Primary.Damage			= 0
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.02
SWEP.Primary.ClipSize		= -1
SWEP.Primary.Delay			= 0.7
SWEP.Primary.DefaultClip	= -1
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "none"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Delay 		= 1.0
SWEP.Secondary.Ammo			= "none"


local ShootSound = Sound( "weapons/ar2/ar2_altfire.wav" )
local warelement = {
  "air",
  "earth",
  "fire",
  "water"
}

if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
	SWEP.HoldType			= "pistol"
	
end

if ( CLIENT ) then

	SWEP.PrintName			= "Pri Pistol"			
	SWEP.Author				= "Zombie"
	SWEP.Slot				= 0
	SWEP.SlotPos			= 0
	SWEP.Contact			= ""
	SWEP.Purpose			= "WBgun"
	SWEP.Instructions		= "Leftclik:Shoot balls"
	
end

function SWEP:LaunchBall( )
	if (!SERVER) then return end
	local RandAngles = Angle(math.random(0,360),math.random(0,360),math.random(0,360))
	local ply = self.Owner
	local rand = math.random(1, #warelement)
	local bola = ents.Create(warelement[rand].."_ball")
		bola:SetPos(ply:GetShootPos())
		bola:SetAngles( RandAngles )
		bola:Spawn()
		bola:Fire("Kill", "", 20)
        bola.iOwner = ply
	    bola.iOwnerTeam = ply:Team()
		
	local bPhys = bola:GetPhysicsObject()
	local Force = ply:GetAimVector() * 10000
	bPhys:ApplyForceCenter(Force)
	self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end

function SWEP:PrimaryAttack( )
	self:LaunchBall()
	self.Weapon:EmitSound( ShootSound, 75, 110 )
	self.BaseClass.ShootEffects( self )
end

function SWEP:SecondaryAttack( )
	local tr = self.Owner:GetEyeTrace()
	if tr.HitPos:Distance(self.Owner:GetPos()) > 200 then return end
	self.Weapon:EmitSound( "weapons/flame_thrower_airblast.wav", 75, 110 )
	self.Owner:SetVelocity( self.Owner:GetForward() * -660 + Vector( 0, 0, 200 ) )
	self.BaseClass.ShootEffects( self )
	
	//effect
	local effectdata = EffectData()
	effectdata:SetStart( tr.HitPos + Vector(0,0,10) )
	effectdata:SetOrigin( tr.HitPos + Vector(0,0,1) )
	effectdata:SetNormal( tr.HitNormal )
	effectdata:SetEntity( self.Owner )
	effectdata:SetAngle( Angle(0,0,0) )
	effectdata:SetMagnitude( 3 )
	effectdata:SetScale( 3 )
	util.Effect( "StunstickImpact", effectdata, true, true ) --ThumperDust
	
	//tempo...
	self.Weapon:SetNextSecondaryFire(CurTime() + 1.2)
end
